package com.stylefeng.guns.modular.customer.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.VisitPic;
import com.stylefeng.guns.modular.customer.service.IVisitPicService;

/**
 * 拜访记录图片控制器
 *
 * @author fengshuonan
 * @Date 2018-04-14 16:48:35
 */
@Controller
@RequestMapping("/visitPic")
public class VisitPicController extends BaseController {

    private String PREFIX = "/customer/visitPic/";

    @Autowired
    private IVisitPicService visitPicService;

    /**
     * 跳转到拜访记录图片首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "visitPic.html";
    }

    /**
     * 跳转到添加拜访记录图片
     */
    @RequestMapping("/visitPic_add")
    public String visitPicAdd() {
        return PREFIX + "visitPic_add.html";
    }

    /**
     * 跳转到修改拜访记录图片
     */
    @RequestMapping("/visitPic_update/{visitPicId}")
    public String visitPicUpdate(@PathVariable Integer visitPicId, Model model) {
        VisitPic visitPic = visitPicService.selectById(visitPicId);
        model.addAttribute("item",visitPic);
        LogObjectHolder.me().set(visitPic);
        return PREFIX + "visitPic_edit.html";
    }

    /**
     * 获取拜访记录图片列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return visitPicService.selectList(null);
    }

    /**
     * 新增拜访记录图片
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(VisitPic visitPic) {
        visitPicService.insert(visitPic);
        return SUCCESS_TIP;
    }

    /**
     * 删除拜访记录图片
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer visitPicId) {
        visitPicService.deleteById(visitPicId);
        return SUCCESS_TIP;
    }

    /**
     * 修改拜访记录图片
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(VisitPic visitPic) {
        visitPicService.updateById(visitPic);
        return SUCCESS_TIP;
    }

    /**
     * 拜访记录图片详情
     */
    @RequestMapping(value = "/detail/{visitPicId}")
    @ResponseBody
    public Object detail(@PathVariable("visitPicId") Integer visitPicId) {
        return visitPicService.selectById(visitPicId);
    }
}
